﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Management;

namespace _02_WMIGrab
{
    class Program
    {
        public static void Main()
        {
            ManagementObjectSearcher query = new
            ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'");
            ManagementObjectCollection queryCollection = query.Get();
            foreach (ManagementObject mo in queryCollection)
            {
                string[] addresses = (string[])mo["IPAddress"];
                string[] subnets = (string[])mo["IPSubnet"];
                string[] defaultgateways =
                     (string[])mo["DefaultIPGateway"];
                Console.WriteLine("Network Card: {0}", mo["Description"]);
                Console.WriteLine("  MAC Address: {0}", mo["MACAddress"]);
                foreach (string ipaddress in addresses)
                    Console.WriteLine("  IP Address: {0}", ipaddress);
                foreach (string subnet in subnets)
                    Console.WriteLine("  Subnet Mask: {0}", subnet);
                if (defaultgateways != null)
                    foreach (string defaultgateway in defaultgateways)
                        Console.WriteLine("  Gateway: {0}", defaultgateway);

                
            }
            Console.ReadLine();
        }
    }

}
